//
//  XHRIllDetailTextField.m
//  快医
//
//  Created by 胥鸿儒 on 16/7/5.
//  Copyright © 2016年 xuhongru. All rights reserved.
//

#import "XHRIllDetailTextField.h"
#import "XHRTextFieldRightView.h"


@interface XHRIllDetailTextField()

/**rightView*/
@property(nonatomic,weak)XHRTextFieldRightView *right_view;

@end

@implementation XHRIllDetailTextField

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self initSettings];
    }
    return self;
}
//初始化设置
- (void)initSettings
{
    self.borderStyle = UITextBorderStyleRoundedRect;
    self.font = [UIFont systemFontOfSize:14];
}
- (void)setType:(XHRTextFieldRightViewType)type
{
    _type = type;
    
    self.right_view.type = type;
    
    if (self.type == XHRTextFieldRightViewTypeSigleButton)
        self.right_view.xhr_Size = CGSizeMake(30, 30);
    else
        self.right_view.xhr_Size = CGSizeMake(160, 30);
    
}
- (BOOL)becomeFirstResponder
{
    self.right_view.isClickTextField = !self.right_view.isClickTextField;
    return NO;
}
- (void)setLoadMoreBlock:(XHRIllDetailTextFieldLoadMoreBlock)loadMoreBlock
{
    _loadMoreBlock = loadMoreBlock;
    self.right_view.loadMoreBlock = self.loadMoreBlock;
}
#pragma mark -
#pragma mark - 懒加载rightView
- (XHRTextFieldRightView *)right_view
{
    if (!_right_view) {
        XHRTextFieldRightView *rightView = [[XHRTextFieldRightView alloc]init];
        self.rightView = rightView;
        self.rightViewMode = UITextFieldViewModeAlways;
        __weak typeof(self)weakSelf = self;
        
        
        rightView.rightViewBlock = ^(BOOL isTreated,NSString *title){
            if (weakSelf.illDetailTextFieldBlock) {
                weakSelf.text = title;
                weakSelf.illDetailTextFieldBlock(isTreated);
            }
            
        };
        _right_view = rightView;
    }
    return _right_view;
}


@end
